/*   1:    */ package com.atomikos.icatch.admin.jmx;
/*   2:    */ 
/*   3:    */ import com.atomikos.icatch.HeuristicMessage;
/*   4:    */ import com.atomikos.icatch.admin.AdminTransaction;
/*   5:    */ import javax.management.MBeanRegistration;
/*   6:    */ import javax.management.MBeanServer;
/*   7:    */ import javax.management.ObjectName;
/*   8:    */ 
/*   9:    */ public abstract class JmxTransaction
/*  10:    */   implements JmxTransactionMBean, MBeanRegistration
/*  11:    */ {
/*  12:    */   private AdminTransaction adminTransaction;
/*  13:    */   private MBeanServer server;
/*  14:    */   private ObjectName name;
/*  15:    */   
/*  16:    */   protected static String convertState(int state)
/*  17:    */   {
/*  18: 63 */     String ret = "UNKNOWN";
/*  19: 65 */     switch (state)
/*  20:    */     {
/*  21:    */     case -3: 
/*  22: 67 */       ret = "ACTIVE";
/*  23: 68 */       break;
/*  24:    */     case -2: 
/*  25: 70 */       ret = "PREPARING";
/*  26: 71 */       break;
/*  27:    */     case 0: 
/*  28: 73 */       ret = "PREPARED";
/*  29: 74 */       break;
/*  30:    */     case 4: 
/*  31: 76 */       ret = "HEURISTIC MIXED";
/*  32: 77 */       break;
/*  33:    */     case 3: 
/*  34: 79 */       ret = "HEURISTIC HAZARD";
/*  35: 80 */       break;
/*  36:    */     case 1: 
/*  37: 82 */       ret = "HEURISTIC COMMIT";
/*  38: 83 */       break;
/*  39:    */     case 2: 
/*  40: 85 */       ret = "HEURISTIC ROLLBACK";
/*  41: 86 */       break;
/*  42:    */     case 6: 
/*  43: 88 */       ret = "COMMITTING";
/*  44: 89 */       break;
/*  45:    */     case 5: 
/*  46: 91 */       ret = "ROLLING BACK";
/*  47: 92 */       break;
/*  48:    */     case 7: 
/*  49: 94 */       ret = "TERMINATED";
/*  50: 95 */       break;
/*  51:    */     }
/*  52:101 */     return ret;
/*  53:    */   }
/*  54:    */   
/*  55:    */   protected static String[] convertHeuristicMessages(HeuristicMessage[] msgs)
/*  56:    */   {
/*  57:106 */     String[] ret = new String[msgs.length];
/*  58:107 */     for (int i = 0; i < msgs.length; i++) {
/*  59:108 */       if (msgs[i] != null) {
/*  60:109 */         ret[i] = msgs[i].toString();
/*  61:    */       } else {
/*  62:111 */         ret[i] = "";
/*  63:    */       }
/*  64:    */     }
/*  65:113 */     return ret;
/*  66:    */   }
/*  67:    */   
/*  68:    */   public JmxTransaction(AdminTransaction adminTransaction)
/*  69:    */   {
/*  70:126 */     this.adminTransaction = adminTransaction;
/*  71:    */   }
/*  72:    */   
/*  73:    */   protected AdminTransaction getAdminTransaction()
/*  74:    */   {
/*  75:132 */     return this.adminTransaction;
/*  76:    */   }
/*  77:    */   
/*  78:    */   protected void unregister()
/*  79:    */   {
/*  80:    */     try
/*  81:    */     {
/*  82:138 */       if (this.server.isRegistered(this.name)) {
/*  83:139 */         this.server.unregisterMBean(this.name);
/*  84:    */       }
/*  85:    */     }
/*  86:    */     catch (Exception e)
/*  87:    */     {
/*  88:141 */       e.printStackTrace();
/*  89:142 */       throw new RuntimeException(e.getMessage());
/*  90:    */     }
/*  91:    */   }
/*  92:    */   
/*  93:    */   public String getTid()
/*  94:    */   {
/*  95:152 */     return this.adminTransaction.getTid();
/*  96:    */   }
/*  97:    */   
/*  98:    */   public String getState()
/*  99:    */   {
/* 100:162 */     return convertState(this.adminTransaction.getState());
/* 101:    */   }
/* 102:    */   
/* 103:    */   public String[] getTags()
/* 104:    */   {
/* 105:172 */     return convertHeuristicMessages(this.adminTransaction.getTags());
/* 106:    */   }
/* 107:    */   
/* 108:    */   public String[] getHeuristicMessages()
/* 109:    */   {
/* 110:181 */     return convertHeuristicMessages(this.adminTransaction.getHeuristicMessages());
/* 111:    */   }
/* 112:    */   
/* 113:    */   public ObjectName preRegister(MBeanServer server, ObjectName name)
/* 114:    */     throws Exception
/* 115:    */   {
/* 116:193 */     this.server = server;
/* 117:194 */     if (name == null) {
/* 118:195 */       name = new ObjectName("atomikos.transactions", "TID", getTid());
/* 119:    */     }
/* 120:196 */     this.name = name;
/* 121:197 */     return name;
/* 122:    */   }
/* 123:    */   
/* 124:    */   public void postRegister(Boolean arg0) {}
/* 125:    */   
/* 126:    */   public void preDeregister()
/* 127:    */     throws Exception
/* 128:    */   {}
/* 129:    */   
/* 130:    */   public void postDeregister() {}
/* 131:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions\3.7.0\transactions-3.7.0.jar
 * Qualified Name:     com.atomikos.icatch.admin.jmx.JmxTransaction
 * JD-Core Version:    0.7.0.1
 */